home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / MAKEDEFS.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  19KB  |  822 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* NetHack may be freely redistributed.  See license for details. */
  3. /* makedefs.c - NetHack version 3.0 */
  4.  
  5.  
  6. #include    "config.h"
  7. #include    "permonst.h"
  8. #include    "objclass.h"
  9. #ifdef MACOS
  10. #include "patchlevel.h"
  11. #endif
  12. #ifdef NULL
  13. #undef NULL
  14. #endif /* NULL */
  15. #define NULL    ((genericptr_t)0)
  16.  
  17. #if defined(VMS) && defined(__GNUC__)
  18.     char *FDECL(ctime, (time_t *));
  19. #endif
  20.  
  21. #if !defined(LINT) && !defined(__GNULINT__)
  22. static    const char    SCCS_Id[] = "@(#)makedefs.c\t3.0\t89/11/15";
  23. #endif
  24.  
  25. #ifdef MSDOS
  26. # if !defined(AMIGA) && !defined(TOS)
  27. # define freopen _freopen
  28. FILE *FDECL(_freopen, (char *,char *,FILE *));
  29. # endif
  30. # undef    exit
  31. extern void FDECL(exit, (int));
  32. # define RDMODE    "r"
  33. # define WRMODE    "w"
  34. #else
  35. # ifdef VMS
  36. #  define RDMODE  "r"
  37. #  define WRMODE  "w"
  38. # else
  39. #  define RDMODE  "r+"
  40. #  define WRMODE  "w+"
  41. # endif
  42. #endif
  43.  
  44. #ifdef MACOS
  45. Boolean FDECL(TouchFile,(char *));
  46. Str255 VolName;
  47. int vRef;
  48. Str255 File;
  49. FInfo info;
  50. OSErr macErr;
  51. #endif
  52.  
  53. /* construct definitions of object constants */
  54.  
  55. #ifdef AMIGA
  56. # define MONST_FILE     "Incl:pm.h"
  57. # define ONAME_FILE     "Incl:onames.h"
  58. # define TRAP_FILE     "Incl:trap.h"
  59. # define DATE_FILE     "Incl:date.h"
  60. # define DATA_FILE     "Auxil:data"
  61. # define RUMOR_FILE     "Auxil:rumors"
  62. #else
  63. # ifndef MACOS
  64. /* construct definitions of object constants */
  65. # define MONST_FILE     "../include/pm.h"
  66. # define ONAME_FILE     "../include/onames.h"
  67. # define TRAP_FILE     "../include/trap.h"
  68. # define DATE_FILE     "../include/date.h"
  69. # define DATA_FILE     "../auxil/data"
  70. # define RUMOR_FILE     "../auxil/rumors"
  71. # else
  72. /*****
  73.  * MAC OS uses ':' to separate dir's and filenames.
  74.  * The following (partial) pathnames assume the makedefs program
  75.  * runs in the same directory as the include and auxil directories
  76.  *****/
  77. # define MONST_FILE    ":include:pm.h"
  78. # define ONAME_FILE    ":include:onames.h"
  79. # define TRAP_FILE    ":include:trap.h"
  80. # define DATE_FILE    ":include:date.h"
  81. # define DATA_FILE    ":auxil:data"
  82. # define RUMOR_FILE    ":auxil:rumors"
  83. #  ifdef AZTEC
  84. #define    perror(x)    Printf(x)
  85. #include "Controls.h"
  86. #  else
  87. #include "ControlMgr.h"
  88. #  endif
  89. # endif
  90. #endif
  91.  
  92.  
  93. char    in_line[256];
  94. extern char *FDECL(gets, (char *));
  95.  
  96. int FDECL(main, (int, char **));
  97. void NDECL(do_objs);
  98. void NDECL(do_traps);
  99. void NDECL(do_data);
  100. void NDECL(do_date);
  101. void NDECL(do_permonst);
  102. void NDECL(do_rumors);
  103.  
  104. char * FDECL(tmpdup, (const char *));
  105.  
  106. #if defined(SYSV) || defined(GENIX) || defined(UNIXDEBUG)
  107. void FDECL(rename, (char *, char *));
  108. #endif
  109.  
  110. #ifdef SMALLDATA
  111. void NDECL(do_monst);
  112. void NDECL(save_resource);
  113. #endif
  114.  
  115. char *FDECL(limit, (char *,int));
  116.  
  117. #if defined(SMALLDATA) && defined(MACOS)
  118. OSErr FDECL(write_resource, (Handle, ResType, short, Str255, short));
  119. # if defined(AZTEC) || defined(THINKC4)
  120. int NDECL(getpid);
  121. # endif
  122. #endif
  123.  
  124. int
  125. main(argc, argv)
  126. int    argc;
  127. char    *argv[];
  128. {
  129.     char    *option;
  130. #ifdef MACOS
  131.     DialogPtr    dialog;
  132.     char    params[3], *options;
  133.     short    itemHit, lastItem, type;
  134.     Rect    box;
  135.     ControlHandle    theControl;
  136.     GrafPtr    oldPort;
  137.  
  138. #define    OK_BUTTON    1
  139. #define    CANCEL_BUTTON    2
  140. #define    FIRST_RADIO_BUTTON    3
  141. #define    ON    1
  142. #define    OFF    0
  143.  
  144.     /* standard Mac initialization */
  145.     InitGraf(&MAINGRAFPORT);
  146.  
  147.     InitFonts();
  148.     InitWindows();
  149.     InitMenus();
  150.     InitCursor();
  151.     FlushEvents(everyEvent,0);
  152.     InitDialogs(NULL);
  153.  
  154.     params[0] = '-';
  155.     options = "DVPRTOM";
  156.     dialog = GetNewDialog(200, 0L, (WindowPtr) -1);
  157.     GetPort(&oldPort);
  158.     SetPort(dialog);
  159.     GetDItem(dialog, OK_BUTTON, &type, &theControl, &box);
  160.     LocalToGlobal(&box.top);
  161.     LocalToGlobal(&box.bottom);
  162.     SetPort(oldPort);
  163.     PenSize(3, 3);
  164.     InsetRect(&box, -4, -4);
  165.     FrameRoundRect(&box, 16, 16);
  166.     PenSize(1, 1);
  167.     itemHit = 0;
  168.     do {
  169.         lastItem = itemHit;
  170.         ModalDialog(NULL, &itemHit);
  171.         if (itemHit != lastItem && itemHit > CANCEL_BUTTON) {
  172.             if (lastItem) {
  173.                 GetDItem(dialog, lastItem, &type,
  174.                         &theControl, &box);
  175.                 SetCtlValue(theControl, OFF);
  176.             }
  177.             params[1] = options[itemHit - FIRST_RADIO_BUTTON];
  178.             GetDItem(dialog, itemHit, &type, &theControl, &box);
  179.             SetCtlValue(theControl, ON);
  180.         }
  181.     } while (itemHit >= FIRST_RADIO_BUTTON);
  182.     DisposDialog(dialog);
  183.     argc = 1;
  184.     if (itemHit == OK_BUTTON && lastItem >= FIRST_RADIO_BUTTON) {
  185.         argc = 2;
  186.         option = params;
  187.  
  188. #else
  189.     if(argc == 2) {
  190.         option = argv[1];
  191. #endif
  192.         switch (option[1]) {
  193.  
  194.         case 'o':
  195.         case 'O':    do_objs();
  196.                 break;
  197.         case 't':
  198.         case 'T':    do_traps();
  199.                 break;
  200.  
  201.         case 'd':
  202.         case 'D':    do_data();
  203.                 break;
  204.  
  205.         case 'v':
  206.         case 'V':    do_date();
  207.                 break;
  208.  
  209.         case 'p':
  210.         case 'P':    do_permonst();
  211.                 break;
  212.  
  213.         case 'r':
  214.         case 'R':    do_rumors();
  215.                 break;
  216. #if defined(SMALLDATA)
  217.         case 'm':
  218.         case 'M':    do_monst();
  219.                 break;
  220.  
  221. #endif    /* SMALLDATA */
  222.  
  223.         default:
  224.                 (void) fprintf(stderr,
  225.                     "Unknown option '%c'.\n", option[1]);
  226.                 (void) fflush(stderr);
  227.                 exit(1);
  228.         }
  229.         exit(0);
  230.     } else    (void) fprintf(stderr, "Bad arg count (%d).\n", argc-1);
  231.     (void) fflush(stderr);
  232.     exit(1);
  233. /*NOTREACHED*/
  234. #if defined(MSDOS) || defined(__GNULINT__)
  235.     return 0;
  236. #endif
  237. }
  238.  
  239. void
  240. do_traps() {
  241.     int    ntrap;
  242.     char    tempfile[30];
  243.  
  244. #ifdef MACOS
  245.     Sprintf(tempfile, ":include:makedefs.%d", getpid());
  246. #else
  247.     Sprintf(tempfile, "makedefs.%d", getpid());
  248. #endif
  249. /* an ugly hack to limit pid-extension to 3 digits */
  250. #ifdef OS2
  251.     if (strlen(tempfile) > 12) tempfile[12] = '\0';
  252. #endif
  253.     if(freopen(tempfile, WRMODE, stdout) == (FILE *)0) {
  254.         perror(tempfile);
  255.         exit(1);
  256.     }
  257.  
  258.     if(freopen(TRAP_FILE, RDMODE, stdin) == (FILE *)0) {
  259.         perror(TRAP_FILE);
  260.         exit(1);
  261.     }
  262.  
  263.     while(gets(in_line) != NULL) {
  264.         (void) puts(in_line);
  265.         if(!strncmp(in_line, "/* DO NOT REMOVE THIS LINE */", 29)) break;
  266.     }
  267.     ntrap = 10;
  268.     Printf("\n");
  269.     Printf("#define\tMGTRP\t\t%d\n", ntrap++);
  270.     Printf("#define\tSQBRD\t\t%d\n", ntrap++);
  271.     Printf("#define\tWEB\t\t%d\n", ntrap++);
  272.     Printf("#define\tSPIKED_PIT\t%d\n", ntrap++);
  273.     Printf("#define\tLEVEL_TELEP\t%d\n", ntrap++);
  274. #ifdef SPELLS
  275.     Printf("#define\tANTI_MAGIC\t%d\n", ntrap++);
  276. #endif
  277.     Printf("#define\tRUST_TRAP\t%d\n", ntrap++);
  278. #ifdef POLYSELF
  279.     Printf("#define\tPOLY_TRAP\t%d\n", ntrap++);
  280. #endif
  281.     Printf("#define\tLANDMINE\t%d\n", ntrap++);
  282.     Printf("\n#define\tTRAPNUM\t%d\n", ntrap);
  283.     Printf("\n#endif /* TRAP_H /**/\n");
  284.     (void) fclose(stdin);
  285.     (void) fclose(stdout);
  286. #if defined(MSDOS) || defined(MACOS)
  287.     remove(TRAP_FILE);
  288. #endif
  289.     rename(tempfile, TRAP_FILE);
  290.     return;
  291. }
  292.  
  293.  
  294. void
  295. do_rumors(){
  296.     char    infile[30];
  297.     long    true_rumor_size;
  298.  
  299.     if(freopen(RUMOR_FILE, WRMODE, stdout) == (FILE *)0) {
  300.         perror(RUMOR_FILE);
  301.         exit(1);
  302.     }
  303.  
  304.     Sprintf(infile, "%s.tru", RUMOR_FILE);
  305.     if(freopen(infile, RDMODE, stdin) == (FILE *)0) {
  306.         perror(infile);
  307.         exit(1);
  308.     }
  309.  
  310.     /* get size of true rumors file */
  311.     (void) fseek(stdin, 0L, 2);
  312.     true_rumor_size = ftell(stdin);
  313.     (void) fwrite((genericptr_t)&true_rumor_size,sizeof(long),1,stdout);
  314.     (void) fseek(stdin, 0L, 0);
  315.  
  316.     /* copy true rumors */
  317.     while(gets(in_line) != NULL)     (void) puts(in_line);
  318.  
  319.     Sprintf(infile, "%s.fal", RUMOR_FILE);
  320.     if(freopen(infile, RDMODE, stdin) == (FILE *)0) {
  321.         perror(infile);
  322.         exit(1);
  323.     }
  324.  
  325.     /* copy false rumors */
  326.     while(gets(in_line) != NULL)     (void) puts(in_line);
  327.  
  328.     (void) fclose(stdin);
  329.     (void) fclose(stdout);
  330. #ifdef MACOS
  331.     Strcpy((char *)File, RUMOR_FILE);
  332.     CtoPstr((char *)File);
  333.     if(!GetVol(VolName, &vRef) && !GetFInfo(File, vRef, &info)){
  334.         info.fdCreator = CREATOR;
  335.         info.fdType = TEXT_TYPE;
  336.         (void) SetFInfo(File, vRef, &info);
  337.     }
  338. #endif
  339.     return;
  340. }
  341.  
  342. #ifdef SYSV
  343. extern long time();
  344. #endif
  345.  
  346. void
  347. do_date(){
  348.     long    clock;
  349.     char    cbuf[30], *c;
  350.  
  351.     if(freopen(DATE_FILE, WRMODE, stdout) == (FILE *)0) {
  352.         perror(DATE_FILE);
  353.         exit(1);
  354.     }
  355.     Printf("/*\tSCCS Id: @(#)date.h\t3.0\t88/11/20 */\n\n");
  356.  
  357. #ifdef KR1ED
  358.     (void) time(&clock);
  359.     Strcpy(cbuf, ctime(&clock));
  360. #else
  361.     (void) time((time_t *)&clock);
  362.     Strcpy(cbuf, ctime((time_t *)&clock));
  363. #endif
  364.     for(c = cbuf; *c != '\n'; c++);    *c = 0; /* strip off the '\n' */
  365.     Printf("const char datestring[] = \"%s\";\n", cbuf);
  366. #ifdef MSDOS
  367.       /* get the time we did a compile for checking save and level files */
  368.     Printf("const long compiletime = %ld;\n", clock);
  369. #endif
  370.  
  371.     (void) fclose(stdout);
  372.     return;
  373. }
  374.  
  375. void
  376. do_data(){
  377.     char    tempfile[30];
  378. #ifndef INFERNO
  379.     boolean    skipping_demons = TRUE;
  380. #endif
  381.     Sprintf(tempfile,
  382. #ifdef OS2
  383.         "%s.bas",
  384. #else
  385.         "%s.base",
  386. #endif
  387.         DATA_FILE);
  388.     if(freopen(tempfile, RDMODE, stdin) == (FILE *)0) {
  389.         perror(tempfile);
  390.         exit(1);
  391.     }
  392.  
  393.     if(freopen(DATA_FILE, WRMODE, stdout) == (FILE *)0) {
  394.         perror(DATA_FILE);
  395.         exit(1);
  396.     }
  397.  
  398.     while(gets(in_line) != NULL) {
  399. #ifndef INFERNO
  400.         if(skipping_demons)
  401.         while(gets(in_line) != NULL && strcmp(in_line, "*centaur"))
  402.             ; /* do nothing */
  403.         skipping_demons = FALSE;
  404. #endif
  405. #ifndef ARMY
  406.         if(!strcmp(in_line, "*soldier")) {
  407.         while(gets(in_line) != NULL && in_line[0] != '\t') ;
  408.         while(gets(in_line) != NULL && in_line[0] == '\t')
  409.             ; /* do nothing */
  410.         }
  411.         else
  412. #endif
  413. #ifndef WORM
  414.         if(!strcmp(in_line, "*long worm")) {
  415.         while(gets(in_line) != NULL && in_line[0] != '\t') ;
  416.         while(gets(in_line) != NULL && in_line[0] == '\t')
  417.             ; /* do nothing */
  418.         }
  419.         else
  420. #endif
  421. #ifndef GOLEMS
  422.         if(!strcmp(in_line, "*golem"))
  423.         while(gets(in_line) != NULL && in_line[0] == '\t')
  424.             ; /* do nothing */
  425.         else
  426. #endif
  427. #ifndef MEDUSA
  428.         if(!strcmp(in_line, "medusa"))
  429.         while(gets(in_line) != NULL && in_line[0] == '\t')
  430.             ; /* do nothing */
  431.         else
  432. #endif
  433. #ifndef NAMED_ITEMS
  434.         if(!strcmp(in_line, "snickersnee")
  435.         || !strcmp(in_line, "orcrist")
  436.           )
  437.         while(gets(in_line) != NULL && in_line[0] == '\t')
  438.             ; /* do nothing */
  439.         else
  440. #endif
  441. #ifndef TOLKIEN
  442.         if(!strcmp(in_line, "hobbit"))
  443.         while(gets(in_line) != NULL && in_line[0] == '\t')
  444.             ; /* do nothing */
  445.         else
  446. #endif
  447.         (void) puts(in_line);
  448.     }
  449.     (void) fclose(stdin);
  450.     (void) fclose(stdout);
  451. #ifdef MACOS
  452.     Strcpy((char *)File, DATA_FILE);
  453.     CtoPstr((char *)File);
  454.     if(!GetVol(VolName, &vRef) && !GetFInfo(File, vRef, &info)){
  455.         info.fdCreator = CREATOR;
  456.         info.fdType = TEXT_TYPE;
  457.         (void) SetFInfo(File, vRef, &info);
  458.     }
  459. #endif
  460.  
  461.     return;
  462. }
  463.  
  464. void
  465. do_permonst()
  466. {
  467.     int    i;
  468.     char    *c, *nam;
  469.  
  470.     if(freopen(MONST_FILE, WRMODE, stdout) == (FILE *)0) {
  471.         perror(MONST_FILE);
  472.         exit(1);
  473.     }
  474.     Printf("/*\tSCCS Id: @(#)pm.h\t3.0\t88/11/20 */\n\n");
  475.     Printf("#ifndef PM_H\n#define PM_H\n");
  476.  
  477.     for(i = 0; mons[i].mlet; i++) {
  478.         Printf("\n#define\tPM_");
  479.         for(nam = c = tmpdup(mons[i].mname); *c; c++) {
  480.             if((*c >= 'a') && (*c <= 'z')) *c -= (char)('a' - 'A');
  481.             else if(*c == ' ' || *c == '-')    *c = '_';
  482.         }
  483.         Printf("%s\t%d", nam, i);
  484.     }
  485.     Printf("\n\n#define\tNUMMONS\t%d\n", i);
  486.     Printf("\n#endif /* PM_H /**/\n");
  487.     (void) fclose(stdout);
  488.     return;
  489. }
  490.  
  491. static    char    temp[32];
  492.  
  493. char *
  494. limit(name,pref)    /* limit a name to 30 characters length */
  495. char    *name;
  496. int    pref;
  497. {
  498.     (void) strncpy(temp, name, pref ? 26 : 30);
  499.     temp[pref ? 26 : 30] = 0;
  500.     return temp;
  501. }
  502.  
  503. void
  504. do_objs()
  505. {
  506.     int i = 0, sum = 0;
  507.     char *c, *objnam;
  508. #ifdef SPELLS
  509.     int nspell = 0;
  510. #endif
  511.     int prefix = 0;
  512.     char let = '\0';
  513.     boolean    sumerr = FALSE;
  514.  
  515.     if(freopen(ONAME_FILE, WRMODE, stdout) == (FILE *)0) {
  516.         perror(ONAME_FILE);
  517.         exit(1);
  518.     }
  519.     Printf("/*\tSCCS Id: @(#)onames.h\t3.0\t89/01/10 */\n\n");
  520.     Printf("#ifndef ONAMES_H\n#define ONAMES_H\n\n");
  521.  
  522.     for(i = 0; !i || objects[i].oc_olet != ILLOBJ_SYM; i++) {
  523.         if (!(objnam = tmpdup(objects[i].oc_name))) continue;
  524.  
  525.         /* make sure probabilities add up to 1000 */
  526.         if(objects[i].oc_olet != let) {
  527.             if (sum && sum != 1000) {
  528.                 (void) fprintf(stderr,
  529.                     "prob error for %c (%d%%)", let, sum);
  530.                 (void) fflush(stderr);
  531.                 sumerr = TRUE;
  532.             }
  533.             let = objects[i].oc_olet;
  534.             sum = 0;
  535.         }
  536.  
  537.         for(c = objnam; *c; c++) {
  538.             if((*c >= 'a') && (*c <= 'z')) *c -= (char)('a' - 'A');
  539.             else if(*c == ' ' || *c == '-')    *c = '_';
  540.         }
  541.  
  542.         switch (let) {
  543.             case WAND_SYM:
  544.             Printf("#define\tWAN_"); prefix = 1; break;
  545.             case RING_SYM:
  546.             Printf("#define\tRIN_"); prefix = 1; break;
  547.             case POTION_SYM:
  548.             Printf("#define\tPOT_"); prefix = 1; break;
  549. #ifdef SPELLS
  550.             case SPBOOK_SYM:
  551.             Printf("#define\tSPE_"); prefix = 1; nspell++; break;
  552. #endif
  553.             case SCROLL_SYM:
  554.             Printf("#define\tSCR_"); prefix = 1; break;
  555.             case GEM_SYM:
  556.             /* avoid trouble with stupid C preprocessors */
  557.             if(objects[i].oc_material == GLASS) {
  558.                 Printf("/* #define\t%s\t%d */\n",
  559.                             objnam, i);
  560.                 prefix = -1;
  561.                 break;
  562.             }
  563.             default:
  564.             Printf("#define\t");
  565.         }
  566.         if (prefix >= 0)
  567.             Printf("%s\t%d\n", limit(objnam, prefix), i);
  568.         prefix = 0;
  569.  
  570.         sum += objects[i].oc_prob;
  571.     }
  572.  
  573.     /* check last set of probabilities */
  574.     if (sum && sum != 1000) {
  575.         (void) fprintf(stderr,
  576.             "prob error for %c (%d%%)", let, sum);
  577.         (void) fflush(stderr);
  578.         sumerr = TRUE;
  579.     }
  580.  
  581.     Printf("#define\tLAST_GEM\t(JADE+1)\n");
  582. #ifdef SPELLS
  583.     Printf("#define\tMAXSPELL\t%d\n", nspell+1);
  584. #endif
  585.     Printf("#define\tNROFOBJECTS\t%d\n", i-1);
  586.     Printf("\n#endif /* ONAMES_H /**/\n");
  587.     (void) fclose(stdout);
  588.     if (sumerr) exit(1);
  589.     return;
  590. }
  591.  
  592. char *
  593. tmpdup(str)
  594. const char *str;
  595. {
  596.     static char buf[128];
  597.  
  598.     if (!str) return (char *)0;
  599.     (void)strncpy(buf, str, 127);
  600.     return buf;
  601. }
  602.  
  603. #if defined(SYSV) || defined(GENIX) || defined(UNIXDEBUG)
  604. void
  605. rename(oldname, newname)
  606. char    *oldname, *newname;
  607. {
  608.     if (strcmp(oldname, newname)) {
  609.         (void) unlink(newname);
  610.         (void) link(oldname, newname);
  611.         (void) unlink(oldname);
  612.     }
  613.     return;
  614. }
  615. #endif
  616.  
  617. #ifdef MSDOS
  618. # if !defined(AMIGA) && !defined(TOS)
  619. /* Get around bug in freopen when opening for writing    */
  620. /* Supplied by Nathan Glasser (nathan@mit-eddie)    */
  621. #undef freopen
  622. FILE *
  623. _freopen(fname, fmode, fp)
  624. char *fname, *fmode;
  625. FILE *fp;
  626. {
  627.     if (!strncmp(fmode,"w",1))
  628.     {
  629.     FILE *tmpfp;
  630.  
  631.     if ((tmpfp = fopen(fname,fmode)) == (FILE *)0)
  632.         return (FILE *)0;
  633.     if (dup2(fileno(tmpfp),fileno(fp)) < 0)
  634.         return (FILE *)0;
  635.     (void) fclose(tmpfp);
  636.     return fp;
  637.     }
  638.     else
  639.     return freopen(fname,fmode,fp);
  640. }
  641. # endif /* !AMIGA && !TOS */
  642.  
  643. # if defined(__TURBOC__) || defined(AMIGA)
  644. int
  645. getpid()
  646. {
  647.     return 1;
  648. }
  649. # endif
  650. #endif /* MSDOS */
  651.  
  652.  
  653. #if defined(SMALLDATA)
  654. void
  655. do_monst()
  656. {
  657.     Handle    monstData, objData, versData;
  658.     char versStr[32], *vstr = VERSION;
  659.     short i, j, patlev = PATCHLEVEL;
  660.     pmstr    *pmMonst;
  661.     SFReply    reply;
  662.     short    refNum,error;
  663.     Str255    name;
  664.     short    findNamedFile();
  665.     OSErr    write_resource();
  666.  
  667.     for(i = 0; mons[i].mlet; i++) {
  668.         ;
  669.     }
  670.     i++;
  671.  
  672.     /*
  673.      * convert to struct where character arrays instead of pointers to
  674.      * strings are used
  675.      */
  676.     pmMonst = (pmstr *)NewPtr(i*sizeof(struct pmstr));
  677.     for (j = 0; j < i; j++) {
  678.         Strcpy(pmMonst[j].mname, mons[j].mname);
  679.         BlockMove(&(mons[j].mlet), &(pmMonst[j].pmp.mlet),
  680.                 (long)sizeof(struct pmpart));
  681.     }
  682.  
  683.     PtrToHand((Ptr)pmMonst, &monstData, (long)(i * sizeof(struct pmstr)));
  684.  
  685.     /* store the object data, in Nethack the char * will be copied in */
  686.     for(i = 0; !i || objects[i].oc_olet != ILLOBJ_SYM; i++) {
  687.         ;
  688.     }
  689.     PtrToHand((Ptr)objects, &objData, ((i+1)*sizeof(struct objclass)));
  690.  
  691.     /* place a small string in the creator resource to identify version */
  692.     Sprintf(versStr, "n%s patchlevel%2d", vstr, patlev);
  693.     *versStr = (int)strlen(VERSION) + 13;  /* n = actual string length */
  694.     PtrToHand(versStr, &versData, sizeof(versStr));
  695.  
  696.     Strcpy((char *)&name[0], "\021nethack.proj.rsrc");
  697.     if (findNamedFile(&name[1], 0, &reply)) {
  698.         (void)strncpy((char *)&name[0],(char *)&reply.fName[0], reply.fName[0]+1);
  699.         if ((refNum = OpenResFile(name)) != -1) {
  700.         if (ResError() == noErr) {
  701.             Strcpy((char *)&name[0], "\012MONST_DATA");
  702.             if (error = write_resource(monstData, HACK_DATA,
  703.                         MONST_DATA, name, refNum)) {
  704.             SysBeep(1);
  705.             Printf("Couldn't add monster data resource.\n");
  706.             }
  707.             Strcpy((char *)&name[0], "\013OBJECT_DATA");
  708.             if (error = write_resource(objData, HACK_DATA,
  709.                         OBJECT_DATA, name, refNum)) {
  710.             SysBeep(1);
  711.             Printf("Couldn't add object data resource.\n");
  712.             }
  713.             Strcpy((char *)&name[0], "\000");
  714.             if (error = write_resource(versData, CREATOR,
  715.                         0, name, refNum)) {
  716.             SysBeep(1);
  717.             Printf("Couldn't add creator info resource.\n");
  718.             }
  719.             CloseResFile(refNum);
  720.             if (ResError() != noErr) {
  721.             SysBeep(1);
  722.             Printf("Couldn't close resource file.");
  723.             }
  724.         }
  725.         }
  726.     }
  727.  
  728.     DisposHandle(monstData);
  729.     DisposHandle(objData);
  730.  
  731.     vRef = reply.vRefNum;
  732.     (void) TouchFile(SHELP);
  733.     (void) TouchFile(HELP);
  734. #ifdef NEWS
  735.     (void) TouchFile("news");
  736. #endif
  737.     if(!TouchFile(RECORD))
  738.         (void) Create(File, vRef, CREATOR, TEXT_TYPE);
  739.  
  740.     (void) TouchFile(CMDHELPFILE);
  741.     (void) TouchFile(HISTORY);
  742.     (void) TouchFile(OPTIONFILE);
  743. #ifdef ORACLE
  744.     (void) TouchFile(ORACLEFILE);
  745. #endif
  746.     (void) TouchFile(LICENSE);
  747. #ifdef MACOS
  748.     (void) TouchFile(MACHELP);
  749. #endif
  750. }
  751.  
  752. Boolean
  753. TouchFile(fname)
  754. char *fname;
  755. {
  756.     SFReply    reply;
  757.     short    findNamedFile();
  758.  
  759.     Strcpy((char *)File, fname);
  760.     CtoPstr((char *)File);
  761.     File[File[0]+1] = 0;
  762.     reply.good = TRUE;
  763.     if(GetFInfo(File, vRef, &info)){
  764.         findNamedFile(&File[1], 2, &reply);
  765.         if(reply.good){
  766.             vRef = reply.vRefNum;
  767.             GetFInfo(File, vRef, &info);
  768.         }
  769.     }
  770.     if(reply.good){
  771.         info.fdCreator = CREATOR;
  772.         info.fdType = TEXT_TYPE;
  773.         (void) SetFInfo(File, vRef, &info);
  774.     }
  775.  
  776.     return(reply.good);
  777. }
  778.  
  779.  
  780.  
  781. OSErr
  782. write_resource(data, theType, resID, resName, refNum)
  783. Handle    data;
  784. ResType    theType;
  785. short    resID;
  786. Str255    resName;
  787. short    refNum;
  788. {
  789.     short    error;
  790.     Handle    theRes;
  791.  
  792.     if (theRes = GetResource(theType, resID)) {
  793.         RmveResource(theRes);
  794.         error = ResError();
  795.         if (error == noErr) {
  796.             DisposHandle(theRes);
  797.             UpdateResFile(refNum);
  798.             error = ResError();
  799.         }
  800.         if (error != noErr) {
  801.             return error;
  802.         }
  803.     } else if (ResError() != resNotFound && ResError() != noErr) {
  804.             return (ResError());
  805.     }
  806.     AddResource(data, theType, resID, resName);
  807.     error = ResError();
  808.     if (error == noErr) {
  809.         WriteResource(data);
  810.         error = ResError();
  811.     }
  812.     return error;
  813. }
  814. # if defined(AZTEC) || defined(THINKC4)
  815. int
  816. getpid()
  817. {
  818.     return 1;
  819. }
  820. # endif
  821. #endif    /* SMALLDATA */
  822.